# crm工作平台社群商机
import time

from Common.basepage import BasePage
from PageLocators.CRM.community_business_loc import CommunityBusinessPageLocator as cb_loc
from TestDatas.CrmData.crm_work_community_business_datas import *


class CrmWorkPage(BasePage):
    """CRM工作平台社群商机"""

    def change_module_page(self, nb1_loc=None, nb2_loc=None,
                           attr_name='class', attr_value='parent-active', nb1_name='', nb2_name=''):
        """
        选择模块页面--导航栏
        :param nb1_loc: 一级导航栏模块定位 # navigation bar 导航栏
        :param nb2_loc: 二级导航栏模块定位
        :param attr_name: 属性名
        :param attr_value: 一级导航栏展开的属性值，默认参数class属性值
        :param nb1_name: 一级导航模块名称
        :param nb2_name: 二级导航模块名称
        """
        time.sleep(5)
        attr_values = self.get_element_attribute(nb1_loc, attr_name, "获取导航栏属性值用于判断一级导航是否展开")
        print('attr_values----', attr_values)
        if attr_value in attr_values:
            self.click_element(nb2_loc, "点击AR二级导航-{}".format(nb2_name))
        else:
            self.click_element(nb1_loc, "点击AR一级导航-{}".format(nb1_name))
            time.sleep(1)
            self.click_element(nb2_loc, "点击AR二级导航-{}".format(nb2_name))
        time.sleep(2)

    # CRM社群商机-陪跑营商机导航
    def go_run_camp_nav(self):
        """打开陪跑营社群商机二级导航页面"""
        self.change_module_page(nb1_loc=cb_loc.nav_cb_loc, nb2_loc=cb_loc.nav_cb_track_loc,
                                attr_name='class', attr_value='expand', nb1_name='社群商机', nb2_name='陪跑营社群商机')

    def date_control(self, date_loc, img_doc):
        """日期控件选择日期"""
        el = self.base_find(date_loc, img_doc)
        time.sleep(3)
        el.click()
        time.sleep(3)

    def run_camp_lst(self):
        """陪跑营社群商机列表"""
        # 时间范围选择
        self.click_element(cb_loc.allocate_time_loc, "分配时间输入框", sleep_time=3)
        self.date_control(cb_loc.left_select_year_loc, "起始年份")
        self.date_control(cb_loc.left_option_year_loc, "选择年")
        self.date_control(cb_loc.left_select_month_loc, "起始月")
        self.date_control(cb_loc.left_option_month_loc, "选择月")
        self.date_control(cb_loc.left_option_day_loc1, "选择起始日")
        self.date_control(cb_loc.left_option_day_loc2, "选择结束日")
        # 顾问名称
        self.input_text(cb_loc.sales_loc, "销售顾问输入框", salesman)
        time.sleep(5)
        self.click_element(cb_loc.option_sales_loc, "点击选项", sleep_time=3)
        # 搜索
        self.click_element(cb_loc.search_loc, "点击搜索", sleep_time=8)
        # 列表数据获取
        data = self.get_element_text(cb_loc.table_date_loc, "陪跑营社群商机列表数据")
        return data


